package o;

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import javax.annotation.Nullable;

final class fxt {
    fxt ʼ;
    boolean ˊ;
    int ˋ;
    int ˎ;
    final byte[] ˏ;
    boolean ॱ;
    fxt ॱॱ;

    fxt() {
        this.ˏ = new byte[8192];
        this.ˊ = true;
        this.ॱ = false;
    }

    fxt(byte[] bArr, int i, int i2, boolean z, boolean z2) {
        this.ˏ = bArr;
        this.ˎ = i;
        this.ˋ = i2;
        this.ॱ = z;
        this.ˊ = z2;
    }

    final fxt ˏ() {
        this.ॱ = true;
        return new fxt(this.ˏ, this.ˎ, this.ˋ, true, false);
    }

    @Nullable
    public final fxt ˎ() {
        fxt o_fxt = this.ʼ != this ? this.ʼ : null;
        this.ॱॱ.ʼ = this.ʼ;
        this.ʼ.ॱॱ = this.ॱॱ;
        this.ʼ = null;
        this.ॱॱ = null;
        return o_fxt;
    }

    public final fxt ˏ(fxt o_fxt) {
        o_fxt.ॱॱ = this;
        o_fxt.ʼ = this.ʼ;
        this.ʼ.ॱॱ = o_fxt;
        this.ʼ = o_fxt;
        return o_fxt;
    }

    public final fxt ˎ(int i) {
        if (i <= 0 || i > this.ˋ - this.ˎ) {
            throw new IllegalArgumentException();
        }
        fxt ˏ;
        if (i >= WXMediaMessage.DESCRIPTION_LENGTH_LIMIT) {
            ˏ = ˏ();
        } else {
            ˏ = fxs.ˋ();
            System.arraycopy(this.ˏ, this.ˎ, ˏ.ˏ, 0, i);
        }
        ˏ.ˋ = ˏ.ˎ + i;
        this.ˎ += i;
        this.ॱॱ.ˏ(ˏ);
        return ˏ;
    }

    public final void ॱ() {
        if (this.ॱॱ == this) {
            throw new IllegalStateException();
        } else if (this.ॱॱ.ˊ) {
            int i = this.ˋ - this.ˎ;
            if (i <= (this.ॱॱ.ॱ ? 0 : this.ॱॱ.ˎ) + (8192 - this.ॱॱ.ˋ)) {
                ˏ(this.ॱॱ, i);
                ˎ();
                fxs.ˊ(this);
            }
        }
    }

    public final void ˏ(fxt o_fxt, int i) {
        if (o_fxt.ˊ) {
            if (o_fxt.ˋ + i > 8192) {
                if (o_fxt.ॱ) {
                    throw new IllegalArgumentException();
                } else if ((o_fxt.ˋ + i) - o_fxt.ˎ > 8192) {
                    throw new IllegalArgumentException();
                } else {
                    System.arraycopy(o_fxt.ˏ, o_fxt.ˎ, o_fxt.ˏ, 0, o_fxt.ˋ - o_fxt.ˎ);
                    o_fxt.ˋ -= o_fxt.ˎ;
                    o_fxt.ˎ = 0;
                }
            }
            System.arraycopy(this.ˏ, this.ˎ, o_fxt.ˏ, o_fxt.ˋ, i);
            o_fxt.ˋ += i;
            this.ˎ += i;
            return;
        }
        throw new IllegalArgumentException();
    }
}
